﻿(function () {
	var m = document.uniqueID && document.compatMode && document.execCommand; // && !window.XMLHttpRequest
	try {
		if (!!m) {
			m("BackgroundImageCache", false, true)
		}
	} catch (e) { };
})();
if (typeof (HTMLElement) != "undefined" && !window.opera) {
	if (HTMLElement.prototype["__defineGetter__"] != null) {
		HTMLElement.prototype.__defineGetter__("canHaveChildren", function () {
			switch (this.tagName.toLowerCase()) {
				case "area": case "base": case "basefont":
				case "col": case "frame": case "hr":
				case "img": case "br": case "input":
				case "link": case "meta": case "isindex":
				case "param": return false;
			}
			return true;
		});
		HTMLElement.prototype.__defineGetter__("innerText", function () {
			return this.textContent;
		});
		HTMLElement.prototype.__defineSetter__("innerText", function (text) {
			this.textContent = text;
		});
		HTMLElement.prototype.__defineGetter__("className", function () {
			return this.getAttribute("class")
		});
		HTMLElement.prototype.__defineSetter__("className", function (className) {
			this.setAttribute("class", className)
		});
		HTMLElement.prototype.__defineGetter__("outerHTML", function () {
			var a = this.attributes, str = "<" + this.tagName, i = 0;
			for (; i < a.length; i++)
				if (a[i].specified) str += " " + a[i].name + '="' + a[i].value + '"';
			if (!this.canHaveChildren) return str + " />";
			return str + ">" + this.innerHTML + "</" + this.tagName + ">";
		});
		HTMLElement.prototype.__defineGetter__("children", function () {
			for (var a = [], j = 0, n, i = 0; i < this.childNodes.length; i++) {
				n = this.childNodes[i];
				if (n.nodeType == 1) {
					a.push(n);
					if (n.name) {
						if (!a[n.name]) a[n.name] = [];
						a[n.name].push(n);
					}
					if (n.id) a[n.id] = n;
				}
			}
			return a;
		});
	}
	if (!HTMLElement.prototype.insertAdjacentHTML)
		HTMLElement.prototype.insertAdjacentHTML = function (where, html) {
			var e = this.ownerDocument.createRange();
			e.setStartBefore(this);
			e = e.createContextualFragment(html);
			switch (where) {
				case 'beforeBegin': this.parentNode.insertBefore(e, this); break;
				case 'afterBegin': this.insertBefore(e, this.firstChild); break;
				case 'beforeEnd': this.appendChild(e); break;
				case 'afterEnd':
					if (!this.nextSibling) this.parentNode.appendChild(e);
					else this.parentNode.insertBefore(e, this.nextSibling);
					break;
			}
		};
	if (!HTMLElement.prototype.swapNode)
		HTMLElement.prototype.swapNode = function (node) {
			var nextSibling = this.nextSibling;
			var parentNode = this.parentNode;
			node.parentNode.replaceChild(this, node);
			parentNode.insertBefore(node, nextSibling);
		}
	if (!HTMLElement.prototype.removeNode)
		HTMLElement.prototype.removeNode = function (removeChild) {
			if (removeChild) this.innerHTML = "";
			var parentNode = this.parentNode;
			this.parentNode.removeChild(this);
		}
}

try {
	if (window.Event && Event.prototype.__defineSetter__) {
		Event.prototype.__defineSetter__("returnValue", function (b) {
			if (!b) this.preventDefault();
			return b;
		});
		Event.prototype.__defineSetter__("cancelBubble", function (b) {
			if (b) this.stopPropagation();
			return b;
		});
		Event.prototype.__defineGetter__("srcElement", function () {
			var node = this.target;
			while (node.nodeType != 1) node = node.parentNode;
			return node;
		});
		Event.prototype.__defineGetter__("fromElement", function () {
			var node;
			if (this.type == "mouseover")
				node = this.relatedTarget;
			else if (this.type == "mouseout")
				node = this.target;
			if (!node) return;
			while (node.nodeType != 1) node = node.parentNode;
			return node;
		});
		Event.prototype.__defineGetter__("toElement", function () {
			var node;
			if (this.type == "mouseout")
				node = this.relatedTarget;
			else if (this.type == "mouseover")
				node = this.target;
			if (!node) return;
			while (node.nodeType != 1) node = node.parentNode;
			return node;
		});
		Event.prototype.__defineGetter__("offsetX", function () {
			return this.layerX;
		});
		Event.prototype.__defineGetter__("offsetY", function () {
			return this.layerY;
		});
	}
} catch (e) { }
if (window.Node) {
	Node.prototype.replaceNode = function (Node) {
		this.parentNode.replaceChild(Node, this);
	}
	Node.prototype.removeNode = function (removeChildren) {
		if (removeChildren) this.innerHTML = "";
		var parentNode = this.parentNode;
		this.parentNode.removeChild(this);
	}
	Node.prototype.swapNode = function (Node) {
		var nextSibling = this.nextSibling;
		var parentNode = this.parentNode;
		node.parentNode.replaceChild(this, Node);
		parentNode.insertBefore(node, nextSibling);
	}
}
if (window.HTMLElement && HTMLElement.prototype.__defineGetter__) {
	HTMLElement.prototype.__defineGetter__("all", function () {
		var a = this.getElementsByTagName("*");
		var node = this;
		a.tags = function (sTagName) {
			return node.getElementsByTagName(sTagName);
		}
		return a;
	});
	HTMLElement.prototype.__defineGetter__("parentElement", function () {
		if (this.parentNode == this.ownerDocument) return null;
		return this.parentNode;
	});
	HTMLElement.prototype.__defineGetter__("children", function () {
		var tmp = [];
		var j = 0;
		var n;
		for (var i = 0; i < this.childNodes.length; i++) {
			n = this.childNodes[i];
			if (n.nodeType == 1) {
				tmp[j++] = n;
				if (n.name) {
					if (!tmp[n.name])
						tmp[n.name] = [];
					tmp[n.name][tmp[n.name].length] = n;
				}
				if (n.id)
					tmp[n.id] = n;
			}
		}
		return tmp;
	});
	HTMLElement.prototype.__defineGetter__("currentStyle", function () {
		return this.ownerDocument.defaultView.getComputedStyle(this, null);
	});
	HTMLElement.prototype.__defineSetter__("outerHTML", function (sHTML) {
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var df = r.createContextualFragment(sHTML);
		this.parentNode.replaceChild(df, this);
		return sHTML;
	});
	HTMLElement.prototype.__defineGetter__("outerHTML", function () {
		var attr;
		var attrs = this.attributes;
		var str = "<" + this.tagName;
		for (var i = 0; i < attrs.length; i++) {
			attr = attrs[i];
			if (attr.specified)
				str += " " + attr.name + '="' + attr.value + '"';
		}
		if (!this.canHaveChildren)
			return str + ">";
		return str + ">" + this.innerHTML + "</" + this.tagName + ">";
	});
	HTMLElement.prototype.__defineGetter__("canHaveChildren", function () {
		switch (this.tagName.toLowerCase()) {
			case "area":
			case "base":
			case "basefont":
			case "col":
			case "frame":
			case "hr":
			case "img":
			case "br":
			case "input":
			case "isindex":
			case "link":
			case "meta":
			case "param":
				return false;
		}
		return true;
	});

	HTMLElement.prototype.__defineSetter__("innerText", function (sText) {
		this.textContent = sText;
	});
	HTMLElement.prototype.__defineGetter__("innerText", function () {
		return this.textContent;
	});
	HTMLElement.prototype.__defineSetter__("outerText", function (sText) {
		var parsedText = document.createTextNode(sText);
		this.outerHTML = parsedText;
		return parsedText;
	});
	HTMLElement.prototype.__defineGetter__("outerText", function () {
		var r = this.ownerDocument.createRange();
		r.selectNodeContents(this);
		return r.toString();
	});
	HTMLElement.prototype.attachEvent = function (sType, fHandler) {
		var shortTypeName = sType.replace(/on/, "");
		fHandler._ieEmuEventHandler = function (e) {
			window.event = e;
			return fHandler();
		}
		this.addEventListener(shortTypeName, fHandler._ieEmuEventHandler, false);
	}
	HTMLElement.prototype.detachEvent = function (sType, fHandler) {
		var shortTypeName = sType.replace(/on/, "");
		if (typeof (fHandler._ieEmuEventHandler) == "function")
			this.removeEventListener(shortTypeName, fHandler._ieEmuEventHandler, false);
		else
			this.removeEventListener(shortTypeName, fHandler, true);
	}
	HTMLElement.prototype.contains = function (Node) {
		do {
			if (Node == this) return true;
			Node = Node.parentNode;
		}
		while (Node);
		return false;
	}
	HTMLElement.prototype.insertAdjacentElement = function (where, parsedNode) {
		switch (where) {
			case "beforeBegin":
				this.parentNode.insertBefore(parsedNode, this);
				break;
			case "afterBegin":
				this.insertBefore(parsedNode, this.firstChild);
				break;
			case "beforeEnd":
				this.appendChild(parsedNode);
				break;
			case "afterEnd":
				if (this.nextSibling)
					this.parentNode.insertBefore(parsedNode, this.nextSibling);
				else
					this.parentNode.appendChild(parsedNode);
				break;
		}
	}
	HTMLElement.prototype.insertAdjacentHTML = function (where, htmlStr) {
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);
		this.insertAdjacentElement(where, parsedHTML);
	}
	HTMLElement.prototype.insertAdjacentText = function (where, txtStr) {
		var parsedText = document.createTextNode(txtStr);
		this.insertAdjacentElement(where, parsedText);
	}
	HTMLElement.prototype.attachEvent = function (sType, fHandler) {
		var shortTypeName = sType.replace(/on/, "");
		fHandler._ieEmuEventHandler = function (e) {
			window.event = e;
			return fHandler();
		}
		this.addEventListener(shortTypeName, fHandler._ieEmuEventHandler, false);
	}
	HTMLElement.prototype.detachEvent = function (sType, fHandler) {
		var shortTypeName = sType.replace(/on/, "");
		if (typeof (fHandler._ieEmuEventHandler) == "function")
			this.removeEventListener(shortTypeName, fHandler._ieEmuEventHandler, false);
		else
			this.removeEventListener(shortTypeName, fHandler, true);
	}
}
if (window.HTMLTableElement && HTMLTableElement.prototype.__defineGetter__) {
	HTMLTableElement.prototype.__defineGetter__("cells", function () {
		var reCells = [];
		var rows = this.rows;
		for (var i = 0, count = rows.length; i < count; i++) {
			var cells = rows[i].cells;
			for (var j = 0, len = cells.length; j < len; j++) {
				reCells.push(cells[j]);
			}
		}
		return reCells;
	});
}